class OrderExaminationsController < ApplicationController

  active_scaffold :order_examination  do |config|
    config.label = " Zlecenia"
    
    config.actions.exclude :update
    config.columns = [
            :id,
            :status,
            :user,
            :executing_user,
            :checking_user,
            :examination_type,
            :patient_data,
            :priorytet
    ]

    config.columns[:examination_type].form_ui  = :select
    config.columns[:patient_data].form_ui  = :select
    
    columns[:id].label = 'Nr. Zlecenia'
    columns[:created_at].label = "Utworzono:"
    columns[:updated_at].label = "Zmodyfikowano:"
    columns[:status].label = "Status badania:"
    columns[:user].label = "Zlecajacy:"
    columns[:user].clear_link
    columns[:executing_user].label = "Wykonujacy:"
    columns[:executing_user].clear_link
    columns[:checking_user].label = "Sprawdzajacy:"
    columns[:checking_user].clear_link
    columns[:examination_type].label = "Nazwa Badania:"
    columns[:patient_data].label = "Pacjent:"
    columns[:priorytet].label = "Priorytet:"

    config.list.columns.exclude  :patient_data, :user, :executing_user, :checking_user
    config.create.columns.exclude :executing_user, :checking_user, :status, :user, :id, :priorytet
    list.per_page = 15
  end

  def before_create_save(record)
    record.user = current_user
  end

    def after_create_save(record)
    record.user = current_user
    flash[:info] = 'Zlecenie zostało dodane'
  end

  def update
    @order_examination = OrderExamination.find(params[:id])

    respond_to do |format|
      if @order_examination.update_attributes(params[:order_examination])
        flash[:notice] = 'OrderExamination was successfully updated.'
        format.html { redirect_to(@order_examination) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @order_examination.errors, :status => :unprocessable_entity }
      end
    end
  end
end
